<div class="content-form">
    <h2><?php echo $this->titulo; ?></h2>
    <div id="content-form">
        <form id="form_curso" action="" method="post" enctype="multipart/form-data">    
            <input type="hidden" id="CUR_ID" name="CUR_ID" value="<?php echo $this->data['CUR_ID']; ?>" />
                
            <div class="col">
                <div class="ln"><strong>Curso</strong> 
                    <?php
                    $obj = new Sistema_Model_DbTable_Cursobase();
                    $obj = $obj->fetchAll('CBS_STA = 1');
                    
                    $objtur = new Sistema_Model_DbTable_Turno();
                    
                    $html = '<select id="CBS_ID" name="CBS_ID" class="chosen-select" required=""><option value="">Nenhum</option>';
                    foreach($obj as $r){   
                        $select = $r['CBS_ID'] == $this->data['CBS_ID'] ? 'selected':''; 
                        $html .= '<option '.$select.' value="'.$r['CBS_ID'].'">'.$r['CBS_NOM'].'</option>'; 
                    }
                    $html .= '</select>';
                    echo $html;
                    ?>
                </div>
                <?php /* <div class="ln"><strong>Nome do Curso</strong> <input type="text" id="CUR_NOM" name="CUR_NOM" value="<?php echo $this->data['CUR_NOM']; ?>" required="" /></div> */ ?>
                <div class="ln"><strong>Ano</strong> <input type="text" id="CUR_ANO" name="CUR_ANO" value="<?php echo $this->data['CUR_ANO']; ?>" required="" class="data_a" /></div>
                <div class="ln"><strong>Tipo de Curso</strong> 
                    <span id="tipo_curso">
                        <?php $arr = dominio::TipoSemestre(); if($this->data['CUR_TPOTMP'] > 0) echo $arr[$this->data['CUR_TPOTMP']]; ?></span>
                    <div style="display: none;">
                    <?php
                        foreach(dominio::TipoSemestre() as $key => $nom){ 
                            $checked = $this->data['CUR_TPOTMP'] == $key ? 'checked=""':'';
                    ?>
                    <label><input type="radio" <?php echo $checked; ?> name="CUR_TPOTMP" id="CUR_TPOTMP" value="<?php echo $key; ?>" class="tpotmp"> <?php echo $nom; ?></label> &nbsp;     
                    <?php } ?>
                    </div>
                </div>
                <div class="ln" id="CUR_SEM"><strong>Semestre</strong> <br>
                    <?php
                        foreach(dominio::Semestres() as $key => $nom){ 
                            $checked = $this->data['CUR_SEM'] == $key ? 'checked=""':'';
                    ?>
                    <label><input type="radio" <?php echo $checked; ?> class="CUR_SEM" name="CUR_SEM" value="<?php echo $key; ?>"> <?php echo $nom; ?></label> &nbsp;     
                    <?php } ?>
                </div>
                <div class="ln"><strong>Carga Horária</strong> <input type="text" id="CUR_HORCRG" name="CUR_HORCRG" value="<?php echo $this->data['CUR_HORCRG']; ?>" class="texto" /></div>
                <?php /* ?>
                <div class="ln"><strong>Turnos</strong> <br>
                   <?php
                    $obj = new Sistema_Model_DbTable_Turno();
                    $obj = $obj->fetchAll(); // 'TUR_ID in()' vir por padrão do curso                    
                    foreach($obj as $r){
                        $checked = $r->TUR_ID == $this->data['TUR_ID'] ? 'checked=""':'';
                    ?>   
                    <label><input type="radio" <?php echo $checked; ?> name="TUR_ID" id="TUR_ID" class="tur_id" value="<?php echo $r['TUR_ID']; ?>" > <?php echo $r['TUR_NOM']; ?></label> &nbsp;  
                    <?php } ?>
                </div>
                */?>
                <div class="ln"><strong>Grupo</strong> 
                    <span id="turma_ajx">
                <?php
                    $arr_cur = array();
                    //$cur = new Sistema_Model_DbTable_Curso();
                    //$r_cur = $cur->fetchAll('CUR_ID <> "'.$this->data['CUR_ID'].'" and CBS_ID = "'.$this->data['CBS_ID'].'" and CUR_STA = 1 and CUR_ANO >= '.date('Y'));
                    
                    $where  = 'CUR_STA = 1 and CUR_ANO >= '.date('Y');
                    if($this->data['CUR_ID'] > 0) $where  .= ' and CUR_ID <> '.$this->data['CUR_ID'];
                    $query = 'SELECT SQL_CACHE DISTINCT CUR_TRM, CURSO.* FROM CURSO WHERE '.$where;
                    $r_cur = $this->db->fetchAll($query);
                    foreach($r_cur as $r_c) $arr_cur[$r_c['CUR_TRM']] = $r_c['CUR_TRM'];
                    
                    $obj = new Sistema_Model_DbTable_Numeroturma();
                    $obj = $obj->fetchAll($obj->select()->where('NRT_STA = 1')->order(array('NRT_SEM ASC','NRT_HOR ASC')));
                    
                    $html = '<select id="CUR_TRM" name="CUR_TRM" class="chosen-select" required=""><option value="">Nenhum</option>';
                    foreach($obj as $r){   
                        if(array_search($r['NRT_ID'], $arr_cur) === FALSE){
                            $select = $r['NRT_ID'] == $this->data['CUR_TRM'] ? 'selected':''; 
                            $html .= '<option '.$select.' value="'.$r['NRT_ID'].'">'.$r['NRT_NOM'].'</option>';
                        }
                    }
                    $html .= '</select>';
                    echo $html;
                    ?></span>
                    <span id="turma_hor_ajx">
                    <?php
                    if($this->data['CUR_TRM'] > 0){
                        $obj = new Sistema_Model_DbTable_Numeroturma();
                        $obj = $obj->fetchRow('NRT_ID = '.$this->data['CUR_TRM']);
                        echo $html = '<div class="ln" style="margin-top: 10px;"><strong></strong> '.Datetools::semana($obj['NRT_SEM'],2).' '.substr($obj['NRT_HOR'],0,5).'</div>';
                    }
                    ?>
                    </span>
                </div>
                <div class="ln"><strong>Número Máx. de Alunos</strong> <input type="text" id="CUR_NMRMAXALU" name="CUR_NMRMAXALU" value="<?php echo $this->data['CUR_NMRMAXALU']; ?>" class="nummin numero" required=""  maxlength="3" /></div>   
                <div class="ln"><strong>Data de Início</strong> <input type="text" id="CUR_DATINI" name="CUR_DATINI" value="<?php echo $this->data['CUR_DATINI']; ?>" class="data"  /></div>
                <div class="ln"><strong>Data de Término</strong> <input type="text" id="CUR_DATFIM" name="CUR_DATFIM" value="<?php echo $this->data['CUR_DATFIM']; ?>" class="data"  /></div>
                
                <div class="ln"><strong>Número de Envio de Redações</strong> <input type="text" id="CUR_REDENV" name="CUR_REDENV" value="<?php echo $this->data['CUR_REDENV']; ?>" class="numero"  /></div>
                <div class="ln"><strong>Número de Correções por Redação</strong> <input type="text" id="CUR_REDCOR" name="CUR_REDCOR" value="<?php echo $this->data['CUR_REDCOR']; ?>" class="numero"  /></div>
                
            </div>
            
            <div class="col">
                <div class="ln"><strong>Valor R$</strong> <input type="text" id="CUR_VLR" name="CUR_VLR" value="<?php echo $this->data['CUR_VLR']; ?>" class="valor" /></div>
                <?php /*
                <div class="ln"><strong>Desconto à vista %</strong> <input type="text" id="CUR_PERDSC" name="CUR_PERDSC" value="<?php echo $this->data['CUR_PERDSC']; ?>" class="valor" /></div>
                */ ?>
                <div class="ln"><strong>Validade da Promoção</strong> <input type="text" id="CUR_DATPRO" name="CUR_DATPRO" value="<?php echo $this->data['CUR_DATPRO']; ?>" class="data"  /></div>
                <div class="ln"><strong>Valor R$ Promocional</strong> <input type="text" id="CUR_VLRPRO" name="CUR_VLRPRO" value="<?php echo $this->data['CUR_VLRPRO']; ?>" class="valor" /></div>
                <div class="ln"><strong class="wdt">Formas de Pagamento</strong> <br>
                <?php
                $arr_set = array();
                if($this->data['CUR_ID']){
                    $obj = new Sistema_Model_DbTable_Cursoforma();
                    $row = $obj->fetchAll('CUR_ID = '.$this->data['CUR_ID']);
                    foreach($row as $r) $arr_set[$r['FOR_ID']] = $r['FOR_ID'];
                }
                
                $obj = new Sistema_Model_DbTable_Formaspagamento();
                $row = $obj->fetchAll('FOR_STA = 1')->toArray();
                $arr = array();
                foreach($row as $r){ 
                    $checked = array_search($r['FOR_ID'], $arr_set) > '' ? 'checked=""':'';
                ?>
                    <label><input type="checkbox" <?php echo $checked; ?> name="FOR_ID[]" id="FOR_ID_<?php echo $r['FOR_ID']; ?>" value="<?php echo $r['FOR_ID']; ?>"> <?php echo $r['FOR_NOM']; ?></label> &nbsp;
                <?php } ?>
                </div>
                
                <div class="ln"><strong>Material</strong>
                <?php
                $list = array();
                if($this->data['CUR_ID'] > 0) foreach(explode(',',$this->data['MTL_ID']) as $temp) $list[$temp] = $temp;
       
                $html = '<select id="MTL_ID" name="MTL_ID[]" class="chosen-select" multiple="multiple">';
                $obj = new Sistema_Model_DbTable_Material();
                $row = $obj->fetchAll()->toArray();
                $arr = array();
                foreach($row as $r){ //$arr[$r['MTL_ID']] = $r['MAT_NOM']; 
                    $selected = array_search($r['MTL_ID'], $list) > '' ? 'selected=""':'';            
                    $html .= '<option '.$selected.' value="'.$r['MTL_ID'].'">'.$r['MTL_NOM'].'</option>'; 
                }
                echo $html .= '</select>';
                ?>
                </div>
                
                <?php if($this->status == TRUE){ ?>
                <div class="ln"><strong>Status do Curso</strong> <br>
                    <label><input type="radio" name="CUR_STA" id="CUR_STA" value="1" <?php if($this->data['CUR_STA'] == '' || $this->data['CUR_STA'] == 1) echo 'checked=""'; ?>> Ativo</label> &nbsp;
                    <label><input type="radio" name="CUR_STA" id="CUR_STA" value="0" <?php if($this->data['CUR_STA'] == '0') echo 'checked=""'; ?> > Inativo</label>
                </div>
                <?php } ?>
                
                <div>
                    <input type="submit" name="submit" id="submitbutton" value="Salvar" class="btn-frm">

                    <a href="<?php echo $this->urlmodulo.'/'.$this->controller; ?>" class="btn-frm">voltar</a>
                </div>
                
            </div>
        </form>
    </div>
</div>
<script>
dataPicker($('#CUR_DATPRO'));
dataPicker($('#CUR_DATINI'));
dataPicker($('#CUR_DATFIM'));
</script>

